package com.content.view.Frame.MainPanel.MPHome
{
	import com.content.model.Collection.ItemGroup;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.model.OnlineRes.OnlineResHomeVO;
	import com.content.view.Frame.MainPanel.SPBase;
	import com.library.core.IDisposable;
	import com.library.core.UIObject;
	
	import flash.display.Shape;
	import flash.display.Sprite;
	
	public class SPRecommend extends SPBase
	{
		private var _band:Sprite;
		private var _recommandContainer:Sprite;
		
		public function SPRecommend()
		{
			super(this);
			
			_band = new SkinProxy.IMG_MPHome_RecommandBand() as Sprite;
			addChild(_band);
			
			_recommandContainer = new Sprite();
			addChild(_recommandContainer);
		}
		
		private function RemoveAllItem():void{
			var nItem:RecommendItem;
			while(_recommandContainer.numChildren > 0){
				nItem = _recommandContainer.removeChildAt(0) as RecommendItem;
				nItem.Dispose();
			}
		}
		
		override public function SetLayout(areaWidth:int, areaHeight:int):void{
			super.SetLayout(areaWidth, areaHeight);
			
			_band.x = int( (areaWidth - _band.width)/2 );
			_band.y = 10;
			
			_recommandContainer.x = int( (areaWidth - _recommandContainer.width)/2 );
			_recommandContainer.y = _band.y + _band.height + 20;
		}
		
		public function Refresh(itemGroup:ItemGroup):void{
			RemoveAllItem();
			
			var insertX:int = 0;
			var itemVO:OnlineResHomeVO;
			for(var i:uint = 0; i < itemGroup.Length; i++){
				itemVO = itemGroup.Items[i] as OnlineResHomeVO;
				
				var rItem:RecommendItem = new RecommendItem(itemVO);				
				_recommandContainer.addChild(rItem);
				rItem.x = insertX;
				insertX += RecommendItem.WIDTH + 15;
			}
			
			SetLayout(_areaW, _areaH);	// 得到数据后，手动重排内容
		}
		
		override public function Dispose():void
		{
		}
	}
}